package com.sanshengshui.iot.test;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.Unpooled;

import java.util.Iterator;

public class CompositeByteBufExample {

    public static void main(String[] args) {
        CompositeByteBuf compositeByteBuf = Unpooled.compositeBuffer();

        ByteBuf buf1 = Unpooled.buffer().writeBytes(new byte[]{1, 2, 3});
        ByteBuf buf2 = Unpooled.buffer().writeBytes(new byte[]{4, 5, 6});
        compositeByteBuf.addComponent(true, buf1);
        compositeByteBuf.addComponent(true, buf2);

        Iterator<ByteBuf> iterator = compositeByteBuf.iterator();
        while (iterator.hasNext()) {
            ByteBuf component = iterator.next();
            System.out.println(component.toString());
        }
        compositeByteBuf.release();
    }

}
